﻿using System;
using System.Collections.Generic;
using System.Text;

namespace OpenGameEngine.Base
{
    /// <summary>
    /// The game service class
    /// </summary>
    public class GameServices : IServiceProvider
    {
        private Dictionary<Type, Object> _services = new Dictionary<Type, object>();

        /// <summary>
        /// Adds a new service to the collection.
        /// </summary>
        public void AddService<T>(T svc)
        {
            if (_services.ContainsKey(svc.GetType()))
                _services[svc.GetType()] = svc;
            else
                _services.Add(svc.GetType(), svc);
        }

        /// <summary>
        /// Gets a specified service
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        public object GetService(Type serviceType)
        {
            Object o = null;
            _services.TryGetValue(serviceType, out o);

            return o;
        }
    }
}
